﻿<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="../../../assets/docs.css" rel="stylesheet" type="text/css" media="screen" />
<title>MooTools Documentation - Utilities/JSON</title>
</head>

<body>
  <div id="docs" class="doc">
    <div class="methods">
      <h4 class="menu-item"><a href="#JSON">JSON</a></h4>
			<div class="menu-item"><a href="#JSON:encode">encode</a></div>
			<div class="menu-item"><a href="#JSON:decode">decode</a></div>
    </div>
    <div class="l-border r-border span-15 content">
				<h1 id="JSON"><a href="#JSON">Object: JSON</a></h1>

<p class="description">JSON decoder and encoder.</p>

<h2 id="JSON:encode"><a href="#JSON:encode">JSON Method: encode</a></h2>

<p class="description">Converts an object or array to a JSON string.</p>

<h3>Syntax:</h3>

<pre class="javascript"><span class="kw2">var</span> myJSON = JSON.<span class="me1">encode</span><span class="br0">(</span>obj<span class="br0">)</span>;
</pre>

<h3>Arguments:</h3>

<ol>
<li>obj - (<em>object</em>) The object to convert to string.</li>
</ol>
<h3>Returns:</h3>

<ul>
<li>(<em>string</em>) A JSON string.</li>
</ul>
<h3>Examples:</h3>

<pre class="javascript"><span class="kw2">var</span> fruitsJSON = JSON.<span class="me1">encode</span><span class="br0">(</span><span class="br0">{</span>apple: <span class="st0">'red'</span>, lemon: <span class="st0">'yellow'</span><span class="br0">}</span><span class="br0">)</span>; <span class="co1">// returns: '{"apple":"red","lemon":"yellow"}'</span>
</pre>

<h2 id="JSON:decode"><a href="#JSON:decode">JSON Method: decode</a></h2>

<p class="description">Converts a JSON string into a JavaScript object.</p>

<h3>Syntax:</h3>

<pre class="javascript"><span class="kw2">var</span> object = JSON.<span class="me1">decode</span><span class="br0">(</span>string<span class="br0">[</span>, secure<span class="br0">]</span><span class="br0">)</span>;
</pre>

<h3>Arguments:</h3>

<ol>
<li>string - (<em>string</em>) The string to evaluate.</li>
<li>secure - (<em>boolean</em>, optional: defaults to false) If set to true, checks for any hazardous syntax and returns null if any found.</li>
</ol>
<h3>Returns:</h3>

<ul>
<li>(<em>object</em>) The object represented by the JSON string.</li>
</ul>
<h3>Examples:</h3>

<pre class="javascript"><span class="kw2">var</span> myObject = JSON.<span class="me1">decode</span><span class="br0">(</span><span class="st0">'{"apple":"red","lemon":"yellow"}'</span><span class="br0">)</span>; <span class="co1">// returns: {apple: 'red', lemon: 'yellow'}</span>
</pre>

<h3>See Also:</h3>

<ul>
<li><a href="http://www.json.org/">JSON (JavaScript Object Notation)</a></li>
</ul>
<h3>Credits:</h3>

<ul>
<li>JSON test regular expression by <a href="http://crockford.com/">Douglas Crockford</a> and <a href="http://tobielangel.com/">Tobie Langel</a>.</li>
</ul>

    </div>
  </div>
<script type="text/javascript" src="../../../assets/mootools-core-1.3.js"></script>
<script type="text/javascript" src="../../../assets/mootools-more-smoothscroll.js"></script>
<script type="text/javascript" src="../../../assets/doc-assist.js"></script>
</body>
</html>
